﻿@{
    List<SelectListItem> channelList = ViewBag.channelList;
    List<SelectListItem> typeList = new List<SelectListItem>(){
        new SelectListItem(){ Text="所有类型", Value=""},
        new SelectListItem(){ Text="首页", Value="index"},
        new SelectListItem(){ Text="列表页", Value="list"},
        new SelectListItem(){ Text="栏目页", Value="category"},
        new SelectListItem(){ Text="详细页", Value="detail"},
        new SelectListItem(){ Text="插件页", Value="plugin"},
        new SelectListItem(){ Text="其他页", Value="other"}
    };
}
@model DTcms.Model.url_rewrite
<form id="form1" class="layui-form" url="UrlRewriteSave?action=@ViewBag.action&name=@ViewBag.UrlName">
    @Html.AntiForgeryToken()
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="../settings/url_rewrite_list" class="back"><i class="fa fa-mail-reply-all"></i> 返回列表页</a></li>
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="javascript:;">URL配置</a> </li>
                <li><a href="javascript:;">编辑URL配置</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <!--内容-->
    <div class="layui-fluid">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title" id="floatHead">
                <li class="layui-this">URL配置信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属频道</label>
                        <div class="layui-input-block">
                            @Html.DropDownList("channel", new SelectList(channelList, "Value", "Text", Model.channel))
                            <span class="Validform_checktip">如果该页面不属于任何频道，可以忽略该项</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">页面类型</label>
                        <div class="layui-input-block">
                            @Html.DropDownList("type", new SelectList(typeList, "Value", "Text", Model.type), new { datatype = "*", sucmsg = " " })
                            <span class="Validform_checktip">*注意选择正确的面页类型</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">调用名称</label>
                        <div class="layui-input-block">
                            @Html.TextBox("name", Model.name, new { @class = "input txt", datatype = @"/^[a-zA-Z0-9\-\_]{2,50}$/", sucmsg = " " })
                            <span class="Validform_checktip">*调用该条URL配置信息的名称，不可重复</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">生成文件名</label>
                        <div class="layui-input-block">
                            @Html.TextBox("page", Model.page, new { @class = "input txt", datatype = "*", sucmsg = " " })
                            <span class="Validform_checktip">*生成的视图页面名称，格式(页面名称/index)</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">继承类名</label>
                        <div class="layui-input-block">
                            @Html.TextBox("inherit", Model.inherit, new { @class = "input txt", datatype = "*", sucmsg = " " })
                            <span class="Validform_checktip">*该ASPX页面所要继承的类名(MVC下此项已经用不到)</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模板文件名</label>
                        <div class="layui-input-block">
                            @Html.TextBox("templet", Model.templet, new { @class = "input txt", datatype = "*", sucmsg = " " })
                            <span class="Validform_checktip">*该页面的模板名称，扩展名一般是.cshtml</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">每页显示</label>
                        <div class="layui-input-block">
                            @Html.TextBox("pagesize", Model.pagesize, new { @class = "input small", datatype = "n0-9", sucmsg = " " }) 条
                            <span class="Validform_checktip">*当该页面进行分页时启用</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">URL表达式</label>
                        <div class="layui-input-block">
                            <a id="itemAddButton" class="layui-btn layui-btn-primary icon-btn"><i class="iconfont icon-add"></i> 添加表达式</a>
                            <span class="Validform_checktip">*注意，不添加任何表达式则视为不重写</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <div class="table-container">
                                <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
                                    <thead>
                                        <tr>
                                            <th width="30%">重写表达式</th>
                                            <th width="30%">正则表达式</th>
                                            <th width="30%">传输参数</th>
                                            <th width="10%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="var_box">
                                        @{
                                            if (Model.url_rewrite_items != null)
                                            {
                                                foreach (DTcms.Model.url_rewrite_item item in Model.url_rewrite_items)
                                                {
                                                    <tr class="td_c">
                                                        <td>
                                                            <input type="text" name="itemPath" class="layui-input" value="@item.path" style="width:90%;" readonly="readonly" />
                                                        </td>
                                                        <td>
                                                            <input type="text" name="itemPattern" class="layui-input" value="@item.pattern" style="width:90%;" readonly="readonly" />
                                                        </td>
                                                        <td>
                                                            <input type="text" name="itemQuerystring" class="layui-input" value="@item.querystring" style="width:90%;" readonly="readonly" />
                                                        </td>
                                                        <td>
                                                            <a title="编辑" class="img-btn" onclick="showUrlDialog(this);"><i class="iconfont icon-edit"></i></a>
                                                            <a title="删除" class="img-btn" onclick="delUrlNode(this);"><i class="iconfont icon-delete"></i></a>
                                                        </td>
                                                    </tr>
                                                }
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <button class="layui-btn icon-btn" id="btnSubmit"><i class="layui-icon layui-icon-ok"></i>提交保存</button>
            <button class="layui-btn layui-btn-warm icon-btn" name="btnReturn" onclick="javascript:history.back(-1);"><i class="layui-icon layui-icon-return"></i>返回上一页</button>
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript">
        layui.use(['jqueryform', 'validform', 'element'], function () {
            //初始化表单验证
            $("#form1").initValidform('#btnSubmit', 1);

            //添加按钮(点击绑定)
            $("#itemAddButton").click(function () {
                showUrlDialog();
            });

            //创建窗口
            window.showUrlDialog= function(obj) {
                var objNum = arguments.length;
                var d = layer.open({
                    type: 2,
                    area: ['800px', '350px'],
                    title: "URL配置信息",
                    maxmin: true, //开启最大化最小化按钮
                    content: '../dialog/dialog_rewrite',
                    btn: ["确定", '关闭'],
                    btn1: function (index, layero) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        var trHtml = iframeWin.submitForm(obj);
                        if (trHtml.length > 0) {
                            $("#var_box").append(trHtml);
                            layer.close(index);
                        }
                    },
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        //检查是否修改状态
                        if (objNum == 1) {
                            iframeWin.submitValue(obj);
                        }
                    },
                    cancel: function (index, layero) { }
                });
            }

            //删除节点
            window.delUrlNode= function(obj) {
                $(obj).parent().parent().remove();
            }
        });
    </script>
}